package com.cm.caseManagement.controller;

import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmLoansType;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmLoansTypeService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 贷款种类Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/type")
public class CmLoansTypeController extends BaseController
{
    @Autowired
    private ICmLoansTypeService cmLoansTypeService;

    /**
     * 查询贷款种类列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmLoansType cmLoansType)
    {
        startPage();
        List<CmLoansType> list = cmLoansTypeService.selectCmLoansTypeList(cmLoansType);
        return getDataTable(list);
    }

    /**
     * 导出贷款种类列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:type:export')")
    @Log(title = "贷款种类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmLoansType cmLoansType)
    {
        List<CmLoansType> list = cmLoansTypeService.selectCmLoansTypeList(cmLoansType);
        ExcelUtil<CmLoansType> util = new ExcelUtil<CmLoansType>(CmLoansType.class);
        util.exportExcel(response, list, "贷款种类数据");
    }

    /**
     * 获取贷款种类详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmLoansTypeService.selectCmLoansTypeById(id));
    }

    /**
     * 新增贷款种类
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:type:add')")
    @Log(title = "贷款种类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmLoansType cmLoansType)
    {
        return toAjax(cmLoansTypeService.insertCmLoansType(cmLoansType));
    }

    /**
     * 修改贷款种类
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:type:edit')")
    @Log(title = "贷款种类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmLoansType cmLoansType)
    {
        return toAjax(cmLoansTypeService.updateCmLoansType(cmLoansType));
    }

    /**
     * 删除贷款种类
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:type:remove')")
    @Log(title = "贷款种类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmLoansTypeService.deleteCmLoansTypeByIds(ids));
    }
}
